#!/bin/sh

DEFAULT_MIMETYPES_FILE='/usr/share/applications/defaults.list'
MIMETYPE_STR1='x-maemo-highlight/atnd-url=qatnd_harmattan.desktop'
MIMETYPE_STR2='x-maemo-urischeme/atnd=qatnd_harmattan.desktop'

echo "Adding mimetypes"

if [ -f $DEFAULT_MIMETYPES_FILE ]; then
   if grep -qs $MIMETYPE_STR1 $DEFAULT_MIMETYPES_FILE
   then
      echo " x-maemo-highlight/atnd-url already set"
   else
      echo $MIMETYPE_STR1 >> $DEFAULT_MIMETYPES_FILE
      echo " x-maemo-highlight/atnd-url set"
   fi

   if grep -qs $MIMETYPE_STR2 $DEFAULT_MIMETYPES_FILE
   then
      echo " x-maemo-urischeme/atnd already set"
   else
      echo $MIMETYPE_STR2 >> $DEFAULT_MIMETYPES_FILE
      echo " x-maemo-urischeme/atnd set"
   fi
fi

echo "Updating desktop database"
update-desktop-database

/usr/bin/aegis-exec -s -u user dbus-send --dest=com.meego.msyncd --print-reply /synchronizer com.meego.msyncd.installPlugin string:'atnd'

gconftool -s /apps/ControlPanel/ATND/EnableFeed -t bool true

/usr/bin/aegis-exec -s -u user dbus-send --dest=com.meego.msyncd --print-reply /synchronizer com.meego.msyncd.startSync string:'atnd'

# Make sure the installation is always considered successful
exit 0
